<link rel="stylesheet" href="https://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<script src="https://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
	$( ".startdate" ).datepicker();
	$( ".enddate" ).datepicker();
});
</script>
  
<?php
$departmentarray = array();
foreach($departments as $department){
	$departmentarray[$department['Department']['id']] = $department['Department']['title'];
}


//print_r($departmentarray); ?>
<?php
    echo $this->Form->create('User'); ?>
    <?php if($this->Session->read('Auth.User.role') === 'superadmin'): ?>
        <fieldset style="float:left; width:45%">
        <legend>Profile Info:</legend>
        <?php
        echo $this->Form->input('username', array('label' => 'Email'));
        echo $this->Form->input('department_id', array('label' => 'Department', 'options' => $departmentarray));
        echo $this->Form->input('cost', array('label' => 'Cost($/hour)'));
        echo $this->Form->input('publish', array('options' => array(1=>'Publish', 0=>'Unpublish')));
        echo $this->Form->input('role', array('label' => 'Access Level', 'options' => 
                array('registered'=>'Registered', 'managers'=>'Managers', 'special'=>'Special', 'admin'=>'Admin', 'superadmin'=>'Super Admin')));?>
         <ul>
            <li><strong>Registered</strong><em>(all other employees) can access</em>: add/edit timesheets, change password</li>
            <li><strong>Managers</strong><em>(Team leads) can access</em>: view department timesheets, change password, view/add/edit/delete clients, view reports</li>
            <li><strong>Special</strong><em>(e.g CEO) can access</em>: view all timesheets, change password, view reports</li>
            <li><strong>Admin</strong><em>(e.g HR) can access</em>:add/edit timesheets, view/add/edit/delete leave days, change password</li>
            <li><strong>Super Admin</strong><em>(IT) can access</em>: All the sections of the portal</li>
        </ul>
        <?php
        
        ?>
        </fieldset>
    <?php endif; ?>
    
    <fieldset style="float:left; width:45%; margin-right:5%;">
    <legend>Leave Days</legend>
    <a href="javascript:addLeave()">add leave</a>
	<table id="leavedays">
	<?php if($user['User']['leavedays'] == ''){
		$now = strtotime(date('Y-m-d H:i:s')); ?>
    	<tr>
    		<td><?php echo $this->Form->input('leavedays.'.$now.'.startdate', array('label' => 'Start Date'));?></td>
			<td><?php echo $this->Form->input('leavedays.'.$now.'.enddate', array('label' => 'End Date')); ?></td>
            <td><a href="javascript:void(0)" class="removeleave">remove</a></td>
        </tr>
    <?php
	}else{
		$leavedays = json_decode($user['User']['leavedays']);
		/*echo '<pre>';
		print_r($leavedays);
		echo '</pre>';*/
		foreach($leavedays as $key => $leaveday):?>
            <tr>
                <td>
                <label>Start Date</label>
                <input name="data[leavedays][<?php echo $key; ?>][startdate]" class="startdate" readonly="readonly" placeholder="select date" type="text" value="<?php echo $leaveday->startdate; ?>"></td>
                <td>
                <label>End Date</label>
                <input name="data[leavedays][<?php echo $key; ?>][enddate]" class="enddate" readonly="readonly" placeholder="select date" type="text" value="<?php echo $leaveday->enddate; ?>"></td>
                <td><a href="javascript:void(0);" class="removeleave">remove</a></td>
            </tr>
         <?php
		 endforeach;
		 unset($leavedays);
		 ?>
    </table>
    
   
    </fieldset>
	
    <?php
	}
    echo $this->Form->input('id', array('type' => 'hidden'));?>
	<p style="float:left;"><?php echo $this->Form->end('Save User'); ?></p>

